﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AutoFix.ClientComponents;
using AutoFix.Interfaces;
using Common;

namespace AutoFix.Base
{

    /// <summary>
    /// Base Page Class
    /// Base contract to implement in all the ASP.NET pages in the system other master pages.
    /// Responsible to take care applying security policies via master page before catering page to the client.
    /// </summary>
    public abstract class BasePage : System.Web.UI.Page
    {
        #region [Protected Members]

        /// <summary>
        /// The page session
        /// </summary>
        protected AppSession PageSession = new AppSession();

        #endregion

        #region [Protected Properties]

        /// <summary>
        /// Gets or sets a value indicating whether [is login page].
        /// </summary>
        /// <value>
        ///   <c>true</c> if [is login page]; otherwise, <c>false</c>.
        /// </value>
        protected abstract bool IsLoginPage { get; }

        /// <summary>
        /// Gets or sets a value indicating whether [is anonymous page].
        /// </summary>
        /// <value>
        ///   <c>true</c> if [is anonymous page]; otherwise, <c>false</c>.
        /// </value>
        protected abstract bool IsAnonymousPage { get; }
        /// <summary>
        /// Gets the name of the page.
        /// </summary>
        /// <value>
        /// The name of the page.
        /// </value>
        protected abstract string PageName { get; }
        /// <summary>
        /// Gets the authorized user types.
        /// </summary>
        /// <value>
        /// The authorized user types.
        /// </value>
        protected abstract List<UserType> AuthorizedUserTypes { get; }

        #endregion

        #region [Event Handlers]

        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            try
            {
                if (!this.IsPostBack)
                {
                    if (this.Master is IMaster)
                    {
                        IMaster master = this.Master as IMaster;
                        master.InitializeSecurityPolicy(this.IsLoginPage, this.IsAnonymousPage, this.PageName, this.AuthorizedUserTypes);
                    }
                }
            }
            catch (Exception eX)
            {
            }

            base.OnLoad(e);
        }

        #endregion
    }
}
